<span class="glyphicon glyphicon-map-marker" aria-hidden="true" style="position: absolute; top: 27px; left: 45px;">
    <span>系统</span> /
    <span>物流配送</span>  /
    <span>编辑发货地址设置</span>
</span>
<row>
    <div class="col-md-12 col-md-offset-2"  style="margin-top: 37px;margin-left: 5px;">
        <form class="form-horizontal" id="form">
            <div class="form-group">
                <label for="name" class="col-md-2 control-label">
                    <div class="text-center">联系人</div>
                </label>
                <div class="col-md-5">
                    <input type="text" class="form-control" id="name"
                           name="name" value="{$list.name}" placeholder="联系人" maxlength="10" />
                    <p style="color: #BBB;">联系人长度最多可输入10个字符</p>
                </div>
            </div>
            <div class="form-group">
                <label for="city_1" class="col-md-2 control-label">
                    <div class="text-center">所在地</div>
                </label>
                <div class="col-md-5" style="display: flex;">
                    <select class="form-control" id="city_1" name="city_1" style="width: 45%;">
                        <option value="-1">请选择</option>
                        {volist name="city_1" id="vo"}
                        {if condition="$list.city_1 == $vo.id"}
                        <option value="{$vo.id}" selected > {$vo.name}</option>
                        {else /}
                        <option value="{$vo.id}">{$vo.name}</option>
                        {/if}
                        {/volist}
                    </select>
                    <select class="form-control" id="city_2" name="city_2" style="width: 45%;margin-left: 25px;">
                        <option value="-1">请选择</option>
                    </select>
                    <select class="form-control" id="city_3" name="city_3" style="width: 45%;margin-left: 25px;">
                        <option value="-1">请选择</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label for="name" class="col-md-2 control-label">
                    <div class="text-center">街道地址</div>
                </label>
                <div class="col-md-5">
                    <input type="text" class="form-control" id="address"
                           name="address" value="{$list.address}" placeholder="街道地址" maxlength="200" />
                </div>
            </div>
            <div class="form-group">
                <label for="name" class="col-md-2 control-label">
                    <div class="text-center">手机号码</div>
                </label>
                <div class="col-md-5">
                    <input type="text" class="form-control" id="phone"
                           name="phone" value="{$list.phone}" placeholder="手机号码" maxlength="11" />
                </div>
            </div>
            <div class="form-group">
                <label for="name" class="col-md-2 control-label">
                    <div class="text-center">电话号码</div>
                </label>
                <div class="col-md-5">
                    <input type="text" class="form-control" id="telphone"
                           name="telphone" value="{$list.telphone}" placeholder="电话号码"/>
                </div>
            </div>
            <div class="form-group">
                <label for="name" class="col-md-2 control-label">
                    <div class="text-center">公司</div>
                </label>
                <div class="col-md-5">
                    <input type="text" class="form-control" id="company"
                           name="company" value="{$list.company}" placeholder="公司"/>
                </div>
            </div>
            <div class="form-group save-btn" style="width: 70%;">
                <button type="button" onclick="Edit({$list.id})" >提交</button>
                <button type="button" onclick="javascript:history.back(-1);return false;" style="background: red;">取消</button>
            </div>
        </form>
    </div>
</row>
<script type="text/javascript">
    function ShopAddress() {
        window.location.href = "{:url('Admin/ShopAddress/Index')}";
    }
    function Edit(id) {
        var name = $("input[id='name']").val();
        var city_1 = document.getElementById("city_1").value;
        var city_2 = document.getElementById("city_2").value;
        var city_3 = document.getElementById("city_3").value;
        var address = $("input[id='address']").val();
        var phone = $("input[id='phone']").val();
        var telphone = $("input[id='telphone']").val();
        var company = $("input[id='company']").val();
        if (name == "") {
            error("请输入联系人姓名");
            return;
        }
        if (city_1 == -1 || city_2 == -1 || city_3 == -1) {
            error("请选择发货的所在地");
            return;
        }
        if (address == "") {
            error("请输入街道地址");
            return;
        }
        if (phone == "") {
            error("请输入手机号码");
            return;
        }
        if (!(/^1[3|4|5|8][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$/.test(phone))) {
            error("手机号码输入有误!")
            return;
        }
        var re = /^[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9][0-9][0-9][0-9]$/;
        if (telphone != "") {
            if (!re.test(telphone)) {
                error("电话号码输入格式有误(****-*******)");
                return "";
            }
        }
        var json = {
            name:name,city_2:city_2,city_3:city_3,city_1:city_1,address:address,
            phone:phone,telphone:telphone,company:company,id:id
        };
        $.ajax({
            type:"post",
            url:"{:url('Admin/ShopAddress/Edit')}",
            data:json,
            success:function (res) {
                if (res == "编辑成功") {
                    success(res);
                    setTimeout("ShopAddress()",2000);
                } else {
                    error(res);
                }
            }
        });
    }
    $(document).ready(function() {
        $("#city_1").change(function () {
            var city_1 = $(this).val();
            if(city_1 == -1){
                var option1=$("<option></option>");
                $(option1).val("-1");
                $(option1).html("请选择");
                $("#city_2").html(option1);
                option1=$("<option></option>");
                $(option1).val("-1");
                $(option1).html("请选择");
                $("#city_3").html(option1);
                return;
            }
            $.ajax({
                type:"post",
                url:"{:url('Admin/City/City')}",
                data:{id:city_1},
                success:function (res) {
                    var operate = res;
                    var option1=$("<option></option>");
                    $(option1).val("-1");
                    $(option1).html("请选择");
                    $("#city_2").html(option1);
                    for(var i in operate){
                        var option=$("<option></option>");
                        $(option).val(operate[i]['id']);
                        $(option).html(operate[i]['name']);
                        $("#city_2").append(option);
                    }
                    option1=$("<option></option>");
                    $(option1).val("-1");
                    $(option1).html("请选择");
                    $("#city_3").html(option1);
                }
            });
        });

        $("#city_2").change(function () {
            var city_2 = $(this).val();
            if(city_2 == -1){
                var option1=$("<option></option>");
                $(option1).val("-1");
                $(option1).html("请选择");
                $("#class_3").html(option1);
                return;
            }
            $.ajax({
                type:"post",
                url:"{:url('Admin/City/City')}",
                data:{id:city_2},
                success:function (res) {
                    var operate = res;
                    var option1=$("<option></option>");
                    $(option1).val("-1");
                    $(option1).html("请选择");
                    $("#city_3").html(option1);
                    for(var i in operate){
                        var option=$("<option></option>");
                        $(option).val(operate[i]['id']);
                        $(option).html(operate[i]['name']);
                        $("#city_3").append(option);
                    }
                }
            });
        });
    });

    $(function () {
        var city_1 = "{$list.city_1}";
        var city_2 = "{$list.city_2}";
        var city_3 = "{$list.city_3}";

        if(city_1 == -1){
            var option1=$("<option></option>");
            $(option1).val("-1");
            $(option1).html("请选择");
            $("#city_2").html(option1);
            option1=$("<option></option>");
            $(option1).val("-1");
            $(option1).html("请选择");
            $("#city_3").html(option1);
            return;
        }
        else {
            $.ajax({
                type: "post",
                url: "{:url('Admin/City/City')}",
                data: {id: city_1},
                success: function (res) {
                    var operate = res;
                    var option1 = $("<option></option>");
                    $(option1).val("-1");
                    $(option1).html("请选择");
                    $("#city_2").html(option1);
                    for (var i in operate) {
                        var option = $("<option></option>");
                        if (operate[i]['id'] == city_2) {
                            option = $("<option selected='selected'></option>");
                        }
                        $(option).val(operate[i]['id']);
                        $(option).html(operate[i]['name']);
                        $("#city_2").append(option);
                    }
                    option1 = $("<option></option>");
                    $(option1).val("-1");
                    $(option1).html("请选择");
                    $("#city_3").html(option1);
                }
            });
        }

        if (city_2 == -1) {
            var city = $("<option></option>");
            $(city).val("-1");
            $(city).html("请选择");
            $("#city_3").html(option1);
            return;
        }
        else {
            $.ajax({
                type:"post",
                url:"{:url('Admin/City/City')}",
                data:{id:city_2},
                success:function (res) {
                    var operate = res;
                    var option1=$("<option></option>");
                    $(option1).val("-1");
                    $(option1).html("请选择");
                    $("#city_3").html(option1);
                    for(var i in operate){
                        var option=$("<option></option>");
                        if (operate[i]["id"] == city_3) {
                            option = $("<option selected='selected'></option>");
                        }
                        $(option).val(operate[i]['id']);
                        $(option).html(operate[i]['name']);
                        $("#city_3").append(option);
                    }
                }
            });
        }

    });
</script>